<!-- S search -->
<app-search-bar
  [submitLoading]="tableParams.loading"
  [searchOptions]="searchOptions"
  labelFlex="80px"
  (onSearch)="queryResetData($event)"
  (onReset)="queryResetData($event)"
>
</app-search-bar>
<!-- E search -->

<nz-card class="m-t-4">
  <div class="opera-wrap">
    <button
      nz-button
      nzType="primary"
      (click)="isSelectVisible = true"
    >新增</button>
  </div>

  <div class="pagination-wrap-position p-t-15">
    <nz-table
      #basicTable
      nzSize="small"
      nzShowSizeChanger
      nzShowQuickJumper
      nzOuterBordered
      [nzFrontPagination]="false"
      [nzLoadingDelay]="100"
      [nzLoading]="tableParams.loading"
      [nzData]="tableParams.tableData"
      [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
      [nzTotal]="tableParams.total"
      [nzPageIndex]="tableParams.page"
      [nzPageSize]="tableParams.pageSize"
      [nzShowTotal]="totalTemplate"
      (nzPageIndexChange)="onPageIndexChange($event)"
      (nzPageSizeChange)="onPageSizeChange($event)"
    >
      <thead>
        <tr>
          <th nzAlign="center">排序</th>
          <th nzAlign="center">游戏ID</th>
          <th nzAlign="center">游戏名称</th>
          <th nzAlign="center">操作</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let data of basicTable.data; let index = index;">
          <!-- 排序 -->
          <td nzAlign="center">{{ tableParams.pageSize * (tableParams.page - 1) + index + 1 }}</td>
          <!-- 游戏ID -->
          <td nzAlign="center">{{ data.id }}</td>
          <!-- 游戏名称 -->
          <td nzAlign="center">{{ data.name || '-' }}</td>
          <!-- 操作 -->
          <td nzAlign="center">
            <button
              nz-button
              nzType="link"
              nzSize="small"
              [disabled]="tableParams.page == 1 && index == 0"
              (click)="moveGameRecommend(data, 1)"
            >上移</button>

            <button
              nz-button
              nzType="link"
              nzSize="small"
              [disabled]="disabledMoveBtn(index)"
              (click)="moveGameRecommend(data, 2)"
            >下移</button>

            <button
              nz-button
              nzType="link"
              nzSize="small"
              nzDanger
              nz-popconfirm
              nzPopconfirmTitle="确认删除?"
              (nzOnConfirm)="deleteGameRecommend(data)"
            >删除</button>
          </td>
        </tr>
      </tbody>
    </nz-table>

    <!-- 分页template -->
    <ng-template #totalTemplate let-total>共有 {{ total }} 条</ng-template>
  </div>
</nz-card>

<game-select-app
  [(ngModel)]="isSelectVisible"
  [extraParams]="{
    isRecommend: 1
  }"
  (selectedEmit)="submitGameData($event)"
></game-select-app>